﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FisheryPlatform.SiteConfig.FileStore;
using System.IO;

namespace FisheryPlatform.Bussiness.FileStore
{
    /// <summary>
    /// 文章静态html上传 \{yyyyMMdd}\{PostId}.{ExtensionName}
    /// </summary>
    public class PostStaticHtmlUploadProvider : FileUploadProviderBase
    {
        public static string defaultExtensionName = "product.aspx";
        public PostStaticHtmlUploadProvider(UploadFileEntity entity)
        {
            base.Init(entity, false, FileUploadConstants.ServiceType_Post, FileUploadConstants.MimeItemKey_Attachment);
        }

        /// <summary>
        /// 文件内容
        /// </summary>
        public static string GetFileContent(DateTime uploadDate, string uploadFileId)
        {
            UploadFileEntity entity = new UploadFileEntity(uploadFileId, defaultExtensionName, new byte[0]);
            entity.UploadDate = uploadDate;
            PostStaticHtmlUploadProvider provider = new PostStaticHtmlUploadProvider(entity);
            return provider.Read(provider.FileServer.RootPath + entity.ServerStorePath);
        }

        /// <summary>
        /// 文件内容
        /// </summary>
        public static string GetFileContent(string publishUrlPath)
        {
            UploadFileEntity entity = new UploadFileEntity("0", defaultExtensionName, new byte[0]);
            PostStaticHtmlUploadProvider provider = new PostStaticHtmlUploadProvider(entity);
            return provider.Read(provider.FileServer.RootPath + publishUrlPath.Replace("/", "\\"));
        }
    }
}
